
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>EventLoop · 👨🏽‍💻前端漫游指南</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="WuXiaolong">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="CSS.html" />
    
    
    <link rel="prev" href="手写call1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                        <b>1.1.</b>
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.2.</b>
                    
                    前端基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.2.1.</b>
                    
                    原生js系列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="手写call1.html">
            
                <a href="手写call1.html">
            
                    
                        <b>1.2.1.1.</b>
                    
                    类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.1.2" data-path="EventLoop.html">
            
                <a href="EventLoop.html">
            
                    
                        <b>1.2.1.2.</b>
                    
                    EventLoop
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="CSS.html">
            
                <a href="CSS.html">
            
                    
                        <b>1.2.2.</b>
                    
                    CSS系列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="布局系列.html">
            
                <a href="布局系列.html">
            
                    
                        <b>1.2.2.1.</b>
                    
                    布局系列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Design/">
            
                <a href="../Design/">
            
                    
                        <b>1.3.</b>
                    
                    前端设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Design/工程模式.html">
            
                <a href="../Design/工程模式.html">
            
                    
                        <b>1.3.1.</b>
                    
                    工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Design/单一模式.html">
            
                <a href="../Design/单一模式.html">
            
                    
                        <b>1.3.2.</b>
                    
                    单一模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../DiyCode/">
            
                <a href="../DiyCode/">
            
                    
                        <b>1.4.</b>
                    
                    手撕代码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../DiyCode/手写call.html">
            
                <a href="../DiyCode/手写call.html">
            
                    
                        <b>1.4.1.</b>
                    
                    手写call
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../DiyCode/手写bind.html">
            
                <a href="../DiyCode/手写bind.html">
            
                    
                        <b>1.4.2.</b>
                    
                    手写bind
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Algorithm/">
            
                <a href="../Algorithm/">
            
                    
                        <b>1.5.</b>
                    
                    前端算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Algorithm/前端算法.html">
            
                <a href="../Algorithm/前端算法.html">
            
                    
                        <b>1.5.1.</b>
                    
                    前端算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Algorithm/统计算法的执行效率和资源消耗.html">
            
                <a href="../Algorithm/统计算法的执行效率和资源消耗.html">
            
                    
                        <b>1.5.2.</b>
                    
                    统计算法的执行效率和资源消耗
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Algorithm/从Chrome V8源码看JavaScript数组.html">
            
                <a href="../Algorithm/从Chrome V8源码看JavaScript数组.html">
            
                    
                        <b>1.5.3.</b>
                    
                    从Chrome V8源码看JavaScript数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Algorithm/LRU算法.html">
            
                <a href="../Algorithm/LRU算法.html">
            
                    
                        <b>1.5.4.</b>
                    
                    LRU算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Algorithm/链表原来如此简单.html">
            
                <a href="../Algorithm/链表原来如此简单.html">
            
                    
                        <b>1.5.5.</b>
                    
                    链表原来如此简单
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../Vue/">
            
                <a href="../Vue/">
            
                    
                        <b>1.6.</b>
                    
                    Vue知识点
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../Vue/Proxy 基本使用与defineProperty.html">
            
                <a href="../Vue/Proxy 基本使用与defineProperty.html">
            
                    
                        <b>1.6.1.</b>
                    
                    Proxy 基本使用与defineProperty
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../Vue/面试题串讲_vue.html">
            
                <a href="../Vue/面试题串讲_vue.html">
            
                    
                        <b>1.6.2.</b>
                    
                    面试题串讲_vue
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../React/">
            
                <a href="../React/">
            
                    
                        <b>1.7.</b>
                    
                    React知识点
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../React/setState解析.html">
            
                <a href="../React/setState解析.html">
            
                    
                        <b>1.7.1.</b>
                    
                    setState解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../React/Fetch异步中止.html">
            
                <a href="../React/Fetch异步中止.html">
            
                    
                        <b>1.7.2.</b>
                    
                    Fetch异步中止
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../React/面试题串讲_react.html">
            
                <a href="../React/面试题串讲_react.html">
            
                    
                        <b>1.7.3.</b>
                    
                    面试题串讲_react
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../ReactNative/">
            
                <a href="../ReactNative/">
            
                    
                        <b>1.8.</b>
                    
                    ReactNative
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../ReactNative/RN分包机制.html">
            
                <a href="../ReactNative/RN分包机制.html">
            
                    
                        <b>1.8.1.</b>
                    
                    RN分包机制
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >EventLoop</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="eventloop">EventLoop</h1>
<p><img src="http://book.52react.cn/uPic/2020%2004%2021%2017%2002%2021%201587459741.png" alt="image-20200421170142958" style="zoom:33%;"></p>
<h3 id="&#x4EFB;&#x52A1;&#x961F;&#x5217;">&#x4EFB;&#x52A1;&#x961F;&#x5217;</h3>
<p><strong><em>&#x540C;&#x6B65;&#x4EFB;&#x52A1;&#x4F18;&#x5148;&#x4E8E;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#x3002;</em></strong></p>
<ul>
<li>&#x5728;&#x540C;&#x6B65;&#x961F;&#x5217;&#x88AB;&#x6267;&#x884C;&#x5B8C;&#x4E4B;&#x524D;&#xFF0C;&#x4EFB;&#x4F55;&#x5F02;&#x6B65;&#x7684;&#x64CD;&#x4F5C;&#x90FD;&#x4E0D;&#x4F1A;&#x88AB;&#x6267;&#x884C;</li>
<li>&#x540C;&#x6B65;&#x4EFB;&#x52A1;&#x6267;&#x884C;&#x5B8C;&#x4E4B;&#x540E;&#x624D;&#x6267;&#x884C;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;</li>
</ul>
<h3 id="&#x8FD0;&#x884C;&#x673A;&#x5236;">&#x8FD0;&#x884C;&#x673A;&#x5236;</h3>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">for</span><span class="token punctuation">(</span>vari<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>i<span class="token operator">&lt;</span><span class="token number">4</span><span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token operator">&lt;</span>
<span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">[</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x6D89;&#x53CA;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x6D89;&#x53CA;&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x53D1;&#x73B0;settimeout&#x4E0D;&#x4F1A;&#x9A6C;&#x4E0A;&#x653E;&#x5230;&#x8FD0;&#x884C;&#x6808;&#x91CC;&#x53BB;&#xFF0C;for&#x5FAA;&#x73AF;&#x4F53;&#x6267;&#x884C;&#x5B8C;&#x624D;&#x53BB;&#x6267;&#x884C;&#x5F02;&#x6B65;&#x961F;&#x5217;&#xFF0C;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x6CA1;&#x6709;&#x5230;&#x65F6;&#x95F4;&#x53BB;&#x6536;&#x7F16;settimeout&#xFF0C;&#x518D;&#x7B49;&#x5F85;&#x4E8B;&#x4EF6;&#x5FAA;&#x73AF;&#x91CC;&#x5904;&#x7406;</p>
<p>Event Loop&#x4E8B;&#x4EF6;&#x5FAA;&#x73AF;</p>
<ol>
<li><p>&#x8FD0;&#x884C;&#x6808;&#x8FD0;&#x884C;&#x7684;&#x662F;&#x540C;&#x6B65;&#x4EFB;&#x52A1;&#x3002;</p>
</li>
<li><p>&#x6D4F;&#x89C8;&#x5668;&#x8BC6;&#x522B;&#x4E86;&#x4E8B;&#x4EF6;&#x662F;&#x4E00;&#x4E2A;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#xFF0C;&#x4ED6;&#x4E0D;&#x4F1A;&#x628A;&#x4ED6;&#x653E;&#x5728;&#x8FD0;&#x884C;&#x6808;&#x91CC;&#xFF0C;&#x800C;&#x662F;&#x62FF;&#x8D70;&#x3002;</p>
</li>
<li><p>&#x62FF;&#x8D70;&#x4E86;&#x4E4B;&#x540E;&#x4E5F;&#x4E0D;&#x662F;&#x7ACB;&#x9A6C;&#x653E;&#x5728;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x540C;&#x6B65;&#x4EFB;&#x52A1;&#x6267;&#x884C;&#x5B8C;&#x4EE5;&#x540E;&#xFF0C;&#x518D;&#x653E;&#x5165;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x3002;</p>
</li>
<li><p>&#x8FD0;&#x884C;&#x6808;&#x91CC;&#x6CA1;&#x6709;&#x4EFB;&#x52A1;&#x4E86;&#xFF0C;&#x5C31;&#x5F00;&#x59CB;&#x6267;&#x884C;&#x5F02;&#x6B65;&#x4EFB;&#x52A1;&#x3002;</p>
</li>
<li><p>&#x6267;&#x884C;&#x5B8C;&#x540E;&#x5982;&#x679C;&#x8FD0;&#x884C;&#x6808;&#x91CC;&#x6CA1;&#x6709;&#x4EFB;&#x52A1;&#x4E86;&#xFF0C;&#x518D;&#x76D1;&#x542C;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x3002;</p>
</li>
<li><p>&#x8FD9;&#x4E2A;&#x5FAA;&#x73AF;&#x7684;&#x8FC7;&#x7A0B;&#x5C31;&#x662F;EventLoop
<img src="../Users/lovewcc/Documents/Gitbook/Base/20190329001003.png" alt=""></p>
</li>
</ol>
<p>&#x5F02;&#x6B65;&#x4EFB;&#x52A1;
setTimeout &#x548C;setInterval
DOM&#x4E8B;&#x4EF6;
Promise</p>
<pre class="language-"><code class="lang-javascript"><span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">4</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;one:&apos;</span> <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&apos;two:&apos;</span> <span class="token operator">+</span> <span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p><img src="../Users/lovewcc/Documents/Gitbook/Base/20190329002750.png" alt=""></p>
<p>&#x603B;&#x7ED3;&#xFF1A;
&#x7406;&#x89E3;js&#x5355;&#x7EBF;&#x7A0B;&#x7684;&#x6982;&#x5FF5; &#x4E00;&#x4E2A;&#x65F6;&#x95F4;&#x53EA;&#x80FD;&#x5E72;&#x4E00;&#x4EF6;&#x4E8B;
&#x7406;&#x89E3;&#x4EFB;&#x52A1;&#x961F;&#x5217;
EventLoop
&#x54EA;&#x4E9B;&#x4F1A;&#x88AB;&#x653E;&#x5165;&#x5F02;&#x6B65;&#x961F;&#x5217;
&#x653E;&#x5165;&#x5F02;&#x6B65;&#x961F;&#x5217;&#x7684;&#x65F6;&#x673A;</p>
<h3 id="&#x6765;&#x4E2A;&#x1F330;">&#x6765;&#x4E2A;&#x1F330;</h3>
<pre class="language-"><code class="lang-js">button<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">&apos;click&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span> <span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span> <span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Microtask 1&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Listener 1&apos;</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
button<span class="token punctuation">.</span>addEventL <span class="token function">istener</span><span class="token punctuation">(</span> <span class="token string">&apos;click&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
<span class="token constant">P</span> romise<span class="token punctuation">.</span> <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span> <span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span> <span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Microtask 2&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Listener 2&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//&#x6267;&#x884C;&#x987A;&#x5E8F;&#x662F; Listener 1 -&gt;Microtask 1 -&gt;Listener 2-&gt;Microtask 2</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x9898;&#x76EE;&#x5BB9;&#x6613;&#x9519;&#x7684;&#x5730;&#x65B9;&#x662F;&#xFF0C;&#x5F53;&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x76D1;&#x542C;&#x4E8B;&#x4EF6;&#x7684;&#x65F6;&#x5019;&#xFF0C;js&#x6267;&#x884C;&#x5B8C;&#xFF0C;&#x8C03;&#x7528;&#x6808;&#x5DF2;&#x7ECF;&#x6E05;&#x7A7A;&#x4E86;&#xFF0C;&#x6240;&#x4EE5;&#x9A6C;&#x4E0A;&#x5C31;&#x6267;&#x884C;&#x4E86;&#x5FAE;&#x4EFB;&#x52A1;&#x3002;</p>
<p>&#x6539;&#x53D8;&#x4E0B;</p>
<pre class="language-"><code class="lang-js">button<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">&apos;click&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span> <span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span> <span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Microtask 1&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Listener 1&apos;</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
button<span class="token punctuation">.</span>addEventL <span class="token function">istener</span><span class="token punctuation">(</span> <span class="token string">&apos;click&apos;</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
<span class="token constant">P</span> romise<span class="token punctuation">.</span> <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span> <span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> console<span class="token punctuation">.</span> <span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Microtask 2&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span> <span class="token string">&apos;Listener 2&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
button<span class="token punctuation">.</span><span class="token function">onClick</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">//&#x6267;&#x884C;&#x8FD9;&#x4E2A;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;</span>
<span class="token comment">//&#x6267;&#x884C;&#x987A;&#x5E8F;&#x662F; Listener 1 -&gt;Listener 2 -&gt; Microtask 1 -&gt; Microtask 2</span>
</code></pre>
<p>&#x4F46;&#x53EA;&#x70B9;&#x51FB;button.onClick() &#x8FD9;&#x4E2A;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#xFF0C;&#x8C03;&#x7528;&#x6808;&#x6CA1;&#x6709;&#x6267;&#x884C;&#x7ED3;&#x675F;&#x524D;&#xFF0C;&#x5FC5;&#x987B;&#x628A;&#x540C;&#x6B65;&#x4EFB;&#x52A1;&#x90FD;&#x6267;&#x884C;&#x7ED3;&#x675F;&#xFF0C;&#x8C03;&#x7528;&#x6808;&#x6E05;&#x7A7A;&#x540E;&#x6267;&#x884C;&#x5FAE;&#x4EFB;&#x52A1;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="手写call1.html" class="navigation navigation-prev " aria-label="Previous page: 类型转换">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="CSS.html" class="navigation navigation-next " aria-label="Next page: CSS系列">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"EventLoop","level":"1.2.1.2","depth":3,"next":{"title":"CSS系列","level":"1.2.2","depth":2,"path":"Base/CSS.md","ref":"Base/CSS.md","articles":[{"title":"布局系列","level":"1.2.2.1","depth":3,"path":"Base/布局系列.md","ref":"Base/布局系列.md","articles":[]}]},"previous":{"title":"类型转换","level":"1.2.1.1","depth":3,"path":"Base/手写call1.md","ref":"Base/手写call1.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","donate","splitter","-anchor-navigation-ex","-sharing","sharing-plus","-highlight","prism","toggle-chapters","-lunr","-search","search-plus"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism.css"]},"github":{"url":"https://github.com/MarioGogogo"},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"http://7q5c2h.com1.z0.glb.clouddn.com/wechatpay.JPG","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"serif","size":2},"anchor-navigation-ex":{"associatedWithSummary":false,"showLevel":true,"multipleH1":true,"mode":"float","pageTop":{"showLevelIcon":false,"level1Icon":"fa fa-hand-o-right","level2Icon":"fa fa-hand-o-right","level3Icon":"fa fa-hand-o-right"}},"sharing":{"qq":false,"all":["weibo","qq","qzone","google","douban"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"toggle-chapters":{},"search-plus":{}},"theme":"default","author":"WuXiaolong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"👨🏽‍💻前端漫游指南","language":"zh-hans","links":{"sidebar":{}},"gitbook":"3.2.3","description":"http://h5web.cc/"},"file":{"path":"Base/EventLoop.md","mtime":"2020-04-21T09:59:09.363Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-22T01:16:46.955Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

